import axios, { AxiosRequestConfig } from 'axios';
const ip="http://8.142.11.143:8301"

/**
 * 获取token
 */
async function getToken() {
    let token;
    await axios({
        method:"post",
        url: ip+'/auth/oauth/token',
        params:{
            grant_type:'client_credentials',
            client:'CY_PRO_MES'
        },
        headers:{
            Authorization:'Basic Q1lfUFJPX01FUzoxMjM0cXdlcg=='
        }
    }).then(function(response) {
        let data = response.data;
        if (data.code == 200) {
            token=data.data.accessToken
        }
    });
    return token
}

/**
 * 请求获取接口数据
 */
export async function getTreeData() {
    let result;
    const token=await getToken()

    await axios({
        method:"get",
        url:ip+'/system/user/findDeptsAndUsers',
        headers:{
            Authorization:'Bearer '+token
        }
    }).then(function(response) {
        let data = response.data;
        if (data.code == 200) {
            result=data
        }
    }).catch(function(error) {
        console.log(error.response);
    });;
    return result
}



